markjwebb
|
Posted: August 02, 2011 21:43 by markjwebb
|
|
I am trying to find the cause of excessive garbage collection in a Java app that uses over 8GB of RAM. Using jmap I have narrowed down the culprit as being a large and rapid amount of char[] creation. 4GB of char[] are being created over a few seconds which then need to be garbage collected. I want to find the places in the source code which are responsible for generating these char[]. I looked at the NewComponent sample, but it's not clear to me how to modify the example to handle primitive array types. I've had a stab at the code below, but would appreciate some guidance from someone who is familiar with how to do this in btrace. Thanks, Mark
package com.sun.btrace.samples;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace public class NewCharArray {
// component count
private static volatile long count;
@OnMethod(
clazz="char[]",
method="<init>"
)
public static void onnew(@Self char[] c) {
// increment counter on constructor entry
count++;
}
@OnTimer(2000)
public static void print() {
// print the counter
println(Strings.strcat("char[] count = ", str(count)));
}
}
|
How to count the number of char[] being allocated
Replies: 1 - Last Post: August 04, 2011 07:36
by: Jaroslav Bachorik
by: Jaroslav Bachorik
showing 1 - 2 of 2
Jaroslav Bachorik
|
Posted: August 04, 2011 07:36 by Jaroslav Bachorik
|
|
It's been discussed here before - in order to intercept the array creation you need to specify a different location. The arrays are special data types and not objects, per se. And as such, no constructor is invoked when creating a new array. You need to use the following code instead:
package com.sun.btrace.samples;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
/**
* This script demonstrates the possibility to intercept
* array creations that are about to be executed from the body of
* a certain method. This is achieved by using the {@linkplain Kind#NEWARRAY}
* location value.
*/
@BTrace public class NewArray {
// component count
private static volatile long count;
@OnMethod(
clazz="/.*/", // tracking in all classes; can be restricted to specific user classes
method="/.*/", // tracking in all methods; can be restricted to specific user methods
location=@Location(value=Kind.NEWARRAY, clazz="char")
)
public static void onnew(@ProbeClassName String pcn, @ProbeMethodName String pmn, String arrType, int dim) {
// pcn - allocation place class name
// pmn - allocation place method name
// **** following two parameters MUST always be in this order
// arrType - the actual array type
// dim - the array dimension
// increment counter on new array
count++;
}
@OnTimer(2000)
public static void print() {
// print the counter
println(Strings.strcat("char[] count = ", str(count)));
}
}
If you'd ever want to inspect the created array (to check its length eg.) you would change location to @Location(value=Kind.NEWARRAY, clazz="char", where=Where.AFTER) and the probe method signature to public static void onnew(@ProbeClassName String pcn, @ProbeMethodName String pmn, @Return char[] ret, String arrType, int dim) -JB- |
Replies: 1 - Last Post: August 04, 2011 07:36
by: Jaroslav Bachorik
by: Jaroslav Bachorik







