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

Thanks for reply, I will give it a try.

From my side:

I see throught native code for filling stack trace - for complete reconstruction needed parsed class object with table of method ids, constans and etc... + code points to string numbers tables - as what I know for HPROF format - all this not included in dump - so at most I can get for each stack frame: 
1. Object from witch call was rerformed, 
2. method reference (in terms of class file format (my sugestion based on native code quick overview))
3. instraction offset in method (in terms of class file format (my sugestion based on native code quick overview))

In my current case class name from our code is all I need, so I stoped with such OQL for getting top 32 frames for each Exception:

SELECT o.@objectId, o.checkoutStackTraceException.backtrace[2][0:-1] 
FROM com.mchange.v2.resourcepool.BasicResourcePool$PunchCard o 
WHERE toString(o.checkoutStackTraceException.backtrace[2][0:-1]).contains("name=ru")

This gives table with 2 columns:

 o.@objectId |o.checkoutStackTraceException.backtrace[2][0:-1]

   1 943 133 |[java.lang.Class [id=0x6c1f93ed8;name=com.mchange.v2.resourcepool.BasicResourcePool], java.lang.Class [id=0x6c1fa91e8;name=com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool], java.lang.Class [id=0x6c1fa91e8;name=com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool], java.lang.Class [id=0x6c1fd0208;name=com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource], java.lang.Class [id=0x6c1f9e738;name=org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider], java.lang.Class [id=0x6c1f69a68;name=org.hibernate.jdbc.ConnectionManager], java.lang.Class [id=0x6c1f69a68;name=org.hibernate.jdbc.ConnectionManager], ... skip long string ...]
...

so with little vim it's became like this:

  1 943 133 |
    at java.lang.Class
    at id=0x6c1f93ed8;name=com.mchange.v2.resourcepool.BasicResourcePool], java.lang.Class
    at id=0x6c1fa91e8;name=com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool], java.lang.Class
    at id=0x6c1fa91e8;name=com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool], java.lang.Class
    at id=0x6c1fd0208;name=com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource], java.lang.Class
    at id=0x6c1f9e738;name=org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider], java.lang.Class
    at id=0x6c1f69a68;name=org.hibernate.jdbc.ConnectionManager], java.lang.Class
    at id=0x6c1f69a68;name=org.hibernate.jdbc.ConnectionManager], java.lang.Class
    at id=0x6c1f69710;name=org.hibernate.jdbc.BorrowedConnectionProxy], java.lang.Class
    at id=0x6c1e4b1d8;name=com.sun.proxy.$Proxy93], java.lang.Class
... skip ...


This may help some one.

вт, 27 авг. 2019 г. в 18:30, Kevin Grigorenko <kevin.grigorenko@xxxxxxxxxx>:
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


_______________________________________________
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


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

Ermolin Ilya

Back to the top