Skip to content

Commit

Permalink
Bug 581644 Allow stack frames as pseudo-objects for HPROF snapshots
Browse files Browse the repository at this point in the history
Fix local variables for finalizer, thread info for stack frames as
locals.

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=581644
Change-Id: I930cd66cdc737fbd14c57703c83f6fc432188a82
  • Loading branch information
ajohnson1 committed Jul 21, 2023
1 parent 8a35d97 commit 615bd8d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2020 SAP AG, IBM Corporation and others.
* Copyright (c) 2008, 2023 SAP AG, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -51,6 +51,7 @@
import org.eclipse.mat.query.annotations.HelpUrl;
import org.eclipse.mat.query.annotations.Icon;
import org.eclipse.mat.snapshot.ISnapshot;
import org.eclipse.mat.snapshot.model.GCRootInfo;
import org.eclipse.mat.snapshot.model.IInstance;
import org.eclipse.mat.snapshot.model.IObject;
import org.eclipse.mat.snapshot.model.NamedReference;
Expand Down Expand Up @@ -116,10 +117,29 @@ private static IObject[] getLocalVarsForThread(IObject thread) throws SnapshotEx
{
List<NamedReference> refs = thread.getOutboundReferences();
List<IObject> result = new ArrayList<IObject>();
for (NamedReference ref : refs)
nextRef: for (NamedReference ref : refs)
{
if (ref instanceof ThreadToLocalReference)
{
ThreadToLocalReference tlr = (ThreadToLocalReference)ref;
for (GCRootInfo gr : tlr.getGcRootInfo())
{
// Allow for stack frames as pseudo-objects
if (gr.getType() == GCRootInfo.Type.JAVA_STACK_FRAME)
{
List<NamedReference> refs2 = ref.getObject().getOutboundReferences();
for (NamedReference ref2 : refs2)
{
if (ref2 instanceof ThreadToLocalReference)
{
result.add(ref2.getObject());
}
}
continue nextRef;
}
}
result.add(ref.getObject());
}
}
return result.toArray(new IObject[result.size()]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2020 SAP AG and IBM Corporation.
* Copyright (c) 2008, 2023 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -54,14 +54,16 @@ static int[] getFinalizerThreads(ISnapshot snapshot) throws Exception
if (finalizerThreadClasses == null || finalizerThreadClasses.isEmpty())
{
// IBM finalizer thread
return getFinalizerThreads2(snapshot, Messages.FinalizerThreadQuery_FinalizerThread);
// Do not translate the name as we are matching with the name of the thread in the snapshot
return getFinalizerThreads2(snapshot, "Finalizer thread"); //$NON-NLS-1$
}
else
{
// Two sorts of finalizer threads
int a[] = getFinalizerThreads1(snapshot);
// Created by System.runFinalization()
int b[] = getFinalizerThreads2(snapshot, Messages.FinalizerThreadQuery_SecondaryFinalizer);
// Do not translate the name as we are matching with the name of the thread in the snapshot
int b[] = getFinalizerThreads2(snapshot, "Secondary finalizer"); //$NON-NLS-1$
int ret[] = new int[a.length + b.length];
System.arraycopy(a, 0, ret, 0, a.length);
System.arraycopy(b, 0, ret, a.length, b.length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2022 SAP AG & IBM Corporation.
* Copyright (c) 2008, 2023 SAP AG & IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -34,6 +34,7 @@
import org.eclipse.mat.snapshot.extension.IRequestDetailsResolver;
import org.eclipse.mat.snapshot.extension.IThreadDetailsResolver;
import org.eclipse.mat.snapshot.extension.IThreadInfo;
import org.eclipse.mat.snapshot.model.GCRootInfo;
import org.eclipse.mat.snapshot.model.IClass;
import org.eclipse.mat.snapshot.model.IObject;
import org.eclipse.mat.snapshot.model.NamedReference;
Expand Down Expand Up @@ -119,7 +120,25 @@ private static int[] getLocalVarsForThread(IObject thread) throws SnapshotExcept
for (NamedReference ref : refs)
{
if (ref instanceof ThreadToLocalReference)
{
result.add(ref.getObjectId());
ThreadToLocalReference tlr = (ThreadToLocalReference)ref;
for (GCRootInfo gr : tlr.getGcRootInfo())
{
// Allow for stack frames as pseudo-objects
if (gr.getType() == GCRootInfo.Type.JAVA_STACK_FRAME)
{
List<NamedReference> refs2 = ref.getObject().getOutboundReferences();
for (NamedReference ref2 : refs2)
{
if (ref2 instanceof ThreadToLocalReference)
{
result.add(ref2.getObjectId());
}
}
}
}
}
}
return result.toArray();
}
Expand Down

0 comments on commit 615bd8d

Please sign in to comment.