Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mat-dev] means for decode java.lang.Throwable#backtrace value to stacktrace

Hi, you can write a query to extract the stacktrace array: https://wiki.eclipse.org/MemoryAnalyzer/Extending_Memory_Analyzer

Example (needs testing, recursion for inner exceptions, etc.):

importorg.eclipse.mat.inspections.collectionextract.CollectionExtractionUtils;
importorg.eclipse.mat.query.IQuery;
importorg.eclipse.mat.query.IResult;
importorg.eclipse.mat.query.annotations.Argument;
importorg.eclipse.mat.query.annotations.Category;
importorg.eclipse.mat.query.annotations.Help;
importorg.eclipse.mat.query.annotations.Name;
importorg.eclipse.mat.query.results.TextResult;
importorg.eclipse.mat.snapshot.ISnapshot;
importorg.eclipse.mat.snapshot.model.IObject;
importorg.eclipse.mat.snapshot.registry.ClassSpecificNameResolverRegistry;
importorg.eclipse.mat.util.IProgressListener;

@Name("Extract Stack")
@Category("My Extensions/JDK")
@Help("If available, extract out a stack.\n\n")
publicclassStackExtractor implementsIQuery
{
    @Argument(isMandatory = true)
    publicIObject object;

    @Argument
    publicISnapshot snapshot;

    @Argument(isMandatory = false)
    publicString field;

    publicIResult execute(IProgressListener listener) throwsException
    {
        StringBuilder sb= newStringBuilder();

        IObject stackHolder= snapshot.getObject(object.getObjectId());

        String[] potentialFields= newString[] { "stack", field};

        IObject stackList= null;

        for(String potentialField: potentialFields)
        {
            if(potentialField== null)
                continue;

            stackList= (IObject) stackHolder.resolveValue(potentialField);

            if(stackList!= null)
                break;
        }

        if(stackList!= null)
        {
            booleanfoundAny= false;
            for(IObject frame: CollectionExtractionUtils.extractList(stackList))
            {
                String output= ClassSpecificNameResolverRegistry.resolve(frame);
                if(output!= null)
                {
                    foundAny= true;
                    sb.append("&nbsp;&nbsp; at " + output+ "<br />");
                }
            }
            if(!foundAny)
            {
                sb.append("Stack empty or unresolvable");
            }
        }
        else
        {
            sb.append("Stack field not found");
        }

        returnnewTextResult(sb.toString(), true);
    }
}

--
Kevin Grigorenko
IBM WebSphere Application Server SWAT




From:        "Илья Ермолин" <ermolinis@xxxxxxxxx>
To:        mat-dev@xxxxxxxxxxx
Date:        08/27/2019 04:05 AM
Subject:        [EXTERNAL] Re: [mat-dev] means for decode java.lang.Throwable#backtrace value        to stacktrace
Sent by:        mat-dev-bounces@xxxxxxxxxxx




Hi!

First of all - thanks for great product for java heap dumps analize!
It's very cool tool that help me and my colleges alot!

My question is: a get Exception in heap dump - witch indicate place of aquire of db connectcion (c3p0 db pool), but this exceptino doesn't contain fillled stackTrace field, just backtrace reference to object array with some strange data without descriptions.

I'm allrady search in java code how do this staff filled, but this path leads to native calls...
Is there namual / description / example of decoding this sctructure? 

--
С Уважением,
Ермолин Илья

Ermolin Ilya


_______________________________________________
mat-dev mailing list
mat-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/mat-dev



Back to the top