Skip to main content

Identifying the Java stack of a thread making an allocation request larger than a certain size


Technote (FAQ)


Question

When you debug Java heap fragmentation or memory problems, it can be helpful to find the stack traces of the thread that makes large allocation requests.

Answer

IBM 1.5 SDK SR10 and later and IBM 1.6 SDK SR5 and later (-Xdump)
IBM 1.3.1 SDK SR10 and later and IBM 1.4.2 SDK SR4 and later (ALLOCATION_THRESHOLD)

To learn about setting the -Xdump:stack:events=allocation,filter environment variable for Application Server versions 6.1 and 7.0 click the link from the following list:
WebSphere Application Server V7.0
WebSphere Application Server V6.1

To learn about setting the ALLOCATION_THRESHOLD environment variable for Application Server versions 5.1.1 and 6.0 click the link from the following list:

WebSphere Application Server V6.0
WebSphere Application Server V5.1.1

**Note: -Xdump and ALLOCATION_THRESHOLD will incur some performance overhead directly proportional to the value the filter/threshold is set.




On IBM 1.3.1 Sovereign SDK Service Release 10 and later (build date of June 5, 2006 and later) and IBM 1.4.2 Sovereign SDK Service Release 4 and later, the environment variable ALLOCATION_THRESHOLD enables a user to identify the Java stack of a thread making an allocation request of larger than the value of this environment variable.


The output is:
    Allocation request for <allocation request> bytes <java stack>

If there is no Java stack, <java stack> becomes No Java Stack.

If you set this option to a value nnn (bytes), whenever an allocation request is made for an object size >= nnn (bytes), the Java stack trace corresponding to the thread requesting the allocation is printed into the standard error log.

Consider the following testcase:

import java.io.*;
public class largeobj {
    static int limit = 20;
    static int size1 = 1000000;
    static int size2 =2*size1;
    public static void main(String []args) throws IOException {
      for (int index0=0; true; index0++) {
      if (0 == index0 % 100) System.out.println(index0);
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(String.class);
    oos.close();
    Object   array1 = null;
    for(int i1=0; i1<limit; i1++) {
      System.out.println("" + i1);
      array1 = new Object[size1] ;
      for (int i2=0; i2<limit; i2++) {
        array1 = new Object[size2];
      }
    }
    array1=null;
    }
      }
}


If you set the option arbitrarily as
export ALLOCATION_THRESHOLD=5000000

You will get messages in the following format during any allocation request larger than or equal to the threshold value:

Allocation request for 8000016 bytes
    at largeobj.main(largeobj.java:18)

You can set the ALLOCATION_THRESHOLD environment variable on IBM WebSphere® Application Server V5.1.1 and V6.0 with 1.4.2 Service Release 4 and later SDKs.

There are instances when this option will not print the Java stack. It will not print Java stack when JVM considers printing of the Java stack as an unsafe operation and so the Java stack will not be printed for some threads. It is considered to be an limitation of this environment variable.

See:
IBM Setting environment entries in WebSphere Application Server




On IBM Java 1.5 SR10 and later and Java 1.6 SR5 and later the -Xdump option can be set to trigger a dump of the stack that makes an allocation request above or within a certain size range.

On the command line or in the generic JVM arguments set:


-Xdump:stack:events=allocation,filter=#10m

This will print the stack information for all allocations over 10m to the native_stderr.log

Or view an allocation within a certain range of values:

-Xdump:stack:events=allocation,filter=#2m..4m

This will print the stack information for all allocations between 2m and 4m to the native_stderr.log

In the native_stderr log locate the output by searching for

"JVMDUMP006I Processing dump event "allocation""


 ./java "-Xdump:stack:events=allocation,filter=#1k" -version
JVMDUMP006I Processing dump event "allocation", detail "1264 bytes, class [B" - please wait.
Thread=main (088B9C4C) Status=Running
at java/lang/System.getPropertyList()[Ljava/lang/String; (Native Method)
at java/lang/System.ensureProperties()V (System.java:254)
at java/lang/System.<clinit>()V (System.java:101)
at java/lang/J9VMInternals.initializeImpl(Ljava/lang/Class;)V (Native Method)
at java/lang/J9VMInternals.initialize(Ljava/lang/Class;)V (J9VMInternals.java:200)
at java/lang/ClassLoader.initializeClassLoaders()V (ClassLoader.java:72)
at java/lang/Thread.initialize(ZLjava/lang/ThreadGroup;Ljava/lang/Thread;)V (Thread.java:325)
at java/lang/Thread.<init>(Ljava/lang/String;Ljava/lang/Object;IZ)V (Thread.java:124)




WebSphere Application Server V7.0 Java 1.6 SR5 or later
To set the following environment entries from the Administrative Console in WebSphere Application Server versions 7.0, follow these steps:
  1. In the administrative console, click Servers > Server Types > WebSphere application servers > server_name. Then, under Server Infrastructure, click Java and process management > Process definition
  2. Select Java Virtual Machine .
  3. Specify values for the JVM settings as needed and click OK.
  4. Click Save on the console task bar.
  5. Restart the application server.




WebSphere Application Server V6.1 Java 1.5 SR10 or later
To set the following environment entries from the Administrative Console in WebSphere Application Server versions 6.1, follow these steps:
  1. In the administrative console, click Servers > Application Servers > server. Then, under Server Infrastructure, click > Java and Process Management > Process Definition .
  2. Select Java Virtual Machine.
  3. Specify values for the JVM settings as needed and click OK.
  4. Click Save on the console task bar.
  5. Restart the application server.





WebSphere Application Server V6.0
To set the following environment entries from the Administrative Console in WebSphere Application Server versions 6.0 and 6.0.1, follow these steps:
  1. Open the Administrative Console.
  2. Select Servers > Application Servers > server_name > Java and Process Management > Process Definition > Environment Entries > New.
  3. If you are using Application Server 6.0.2 or greater, navigate in the Administrative Console to: Servers >Application servers > server_name > (Expand Java and Process Management) > Process Definition > Custom Properties > New
  4. Add the following Name/Value pairs:
    Name: ALLOCATION_THRESHOLD
    Value: value
  5. Make sure that you save your changes to the master configuration and restart the Application Server.


WebSphere Application Server V5.1.1
To set the following Environment Entries from the Administrative Console in WebSphere Application Server 5.1.1, follow these steps:
  1. Open the Administrative Console.
  2. Select Servers > Application Servers > server_name > Process Definition > Environment Entries > New.
  3. Add the following Name/Value pairs:
    Name: ALLOCATION_THRESHOLD
    Value: value
  4. Make sure that you save your changes to the master configuration and restart the Application Server.

Cross reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK

Rate this page:

(0 users)Average rating

Copyright and trademark information

IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.

Rate this page:


(0 users)Average rating

Add comments

Document information

WebSphere Application Server

Java SDK


Software version:
5.1.1, 6.0, 6.1, 7.0


Operating system(s):
AIX, Linux, Windows


Reference #:
1236523


Modified date:
2008-05-22

Translate my page

Content navigation