Using Sun WorkShop

Reordering Program Functions

If text page faults are consuming a lot of your application's time, the Sampling Analyzer can reorder your program, generating a mapfile containing an improved ordering of functions. With the most-used functions grouped together on the same set of pages, a function is more likely to already be in memory when called.

The --M option passes the mapfile to the linker, which then relinks your application and produces a new executable application with a smaller text address space size.

After you have reordered your application you can run a new experiment and compare the original version with the reordered one.

To reorder an application, compile the application using the --xF option.

The --xF option is required for reordering. This option causes the compiler to generate functions that can be relocated independently.

For C applications, type:

cc -xF -c a.c b.c cc -o application_name a.o b.o

For C++ applications, type:

CC -xF -c a.cc b.cc CC -o application_name a.o b.o

For Fortran applications, type:>

f77 -xF -c a.f b.f f77 -o application_name a.o b.o

If you see the following warning message, check any files that are statically linked, such as unshared object and library files, because these files may not have been compiled with the --xF option:


ld: warning: mapfile: text: .text%function_name: object_file_name: Entrance criteria not met the named file, function_name, has not been compiled with the --xF option.

  1. Load the application in Sun WorkShop for debugging.

  2. Start the Sampling Collector by choosing Windows > Sampling Collector from the Debugging window.

  3. Run the application in Sun WorkShop.

  4. Load the specified experiment into the Sampling Analyzer.

  5. Create a reordered map in the Sampling Analyzer by choosing Experiment > Create Mapfile. In the file chooser, enter the samples to be used, the mapfile directory, and the name of the mapfile to be created, and click OK.

    The mapfile contains names of functions that have user CPU time associated with them. It specifies a function ordering that reduces the size of the text address space by sorting profiling data and function sizes in descending order. All functions not listed in the mapfile are placed after the listed functions.

  6. Link the application using the new mapfile.

    For C applications, type:

    cc -Wl -M mapfile_name a.o b.o

    For C++ applications, type:

    CC -M mapfile_name a.o b.o

    For C applications, the --M option causes the compiler to pass --M mapfile_name to the linker.

    For Fortran applications, type:

    f77 -M mapfile_name a.o b.o