Skip to content

Commit

Permalink
Bug 491109 Some collections queries fail for some collections from PHD
Browse files Browse the repository at this point in the history
files

Improve linked list and identity hash maps.

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=491109
Change-Id: Id136f0edec0dde6ca883a88437478a8eab2f74ef
  • Loading branch information
ajohnson1 committed Oct 19, 2023
1 parent 3b75f59 commit 5b49e1a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ public Integer getSize(IObject coll) throws SnapshotException
}
else
{
return ExtractionUtils.getNumberOfNotNullArrayElements(extractEntryIds(coll));
// May not work properly with PHD and null values
int entries[] = extractEntryIds(coll);
int count = 0;
for (int i = 0; i < entries.length; i += 2)
{
if (entries[i] >= 0)
++count;
}
return count;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2015 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 @@ -44,7 +44,8 @@ public int[] extractEntryIds(IObject list) throws SnapshotException
{
IProgressListener listener = new VoidProgressListener();
// If there isn't a size, then use an upper limit in case there is a loop
int size = super.hasSize() ? getSize(list) : 10000000;
Integer s;
int size = super.hasSize() && (s = super.getSize(list)) != null ? s : 10000000;

String taskMsg = MessageUtil.format(Messages.ExtractListValuesQuery_CollectingElements, size,
list.getTechnicalName());
Expand All @@ -63,6 +64,29 @@ public int[] extractEntryIds(IObject list) throws SnapshotException
// Look for the only object field
header = ExtractionUtils.followOnlyOutgoingReferencesExceptLast(leadField, list);
}
if (header == list)
{
// Try without using field names
IObject first = null;
final ISnapshot snapshot = header.getSnapshot();
for (int i : snapshot.getOutboundReferentIds(header.getObjectId()))
{
IObject o = snapshot.getObject(i);
// Exclude the class
if (i != header.getClazz().getObjectId())
{
if (first == null)
first = o;
else if (!first.getClass().equals(o.getClass()))
{
first = null;
break;
}
}
}
if (first != null)
header = first;
}
if (header == null)
return new int[0];

Expand Down Expand Up @@ -152,6 +176,9 @@ public int[] extractEntryIds(IObject list) throws SnapshotException

if (ref != null)
result.add(ref.getObjectId());
// Stop looping to start
if (header == null)
header = current;
previous = current;
current = next;
listener.worked(1);
Expand All @@ -174,7 +201,9 @@ public Integer getSize(IObject coll) throws SnapshotException
{
if (super.hasSize())
{
return super.getSize(coll);
Integer s = super.getSize(coll);
if (s != null)
return s;
}
int entries[] = extractEntryIds(coll);
if (entries == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018,2019 IBM Corporation
* Copyright (c) 2018,2023 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 All @@ -12,10 +12,16 @@
*******************************************************************************/
package org.eclipse.mat.tests.collect;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assume.assumeThat;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;

import org.eclipse.mat.SnapshotException;
import org.eclipse.mat.snapshot.ISnapshot;
import org.eclipse.mat.tests.TestSnapshots;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -35,7 +41,7 @@ public static Collection<Object[]> data()
{
Object[][] data = new Object[][] { { TestSnapshots.ORACLE_JDK7_21_64BIT },
{ TestSnapshots.IBM_JDK8_64BIT_SYSTEM },
// { TestSnapshots.IBM_JDK8_64BIT_HEAP_AND_JAVA }, currently problems with PHD collections
{ TestSnapshots.IBM_JDK8_64BIT_HEAP_AND_JAVA }, // currently problems with PHD collections
{ TestSnapshots.ORACLE_JDK8_05_64BIT },
{ TestSnapshots.OPENJDK_JDK11_04_64BIT } };
return Arrays.asList(data);
Expand All @@ -44,13 +50,18 @@ public static Collection<Object[]> data()
@Test
public void testCollections1() throws SnapshotException
{
testCollections1(TestSnapshots.getSnapshot(snapfile, false), null);
ISnapshot snapshot = TestSnapshots.getSnapshot(snapfile, false);
// works for PHD!
//assumeThat(snapshot.getSnapshotInfo().getProperty("$heapFormat"), not(equalTo((Serializable)"DTFJ-PHD")));
testCollections1(snapshot, null);
}

@Test
public void testCollections2() throws SnapshotException
{
testCollections2(TestSnapshots.getSnapshot(snapfile,false), null);
ISnapshot snapshot = TestSnapshots.getSnapshot(snapfile, false);
assumeThat(snapshot.getSnapshotInfo().getProperty("$heapFormat"), not(equalTo((Serializable)"DTFJ-PHD")));
testCollections2(snapshot, null);
}

@Test
Expand All @@ -68,12 +79,16 @@ public void testCollections4() throws SnapshotException
@Test
public void testCollections5() throws SnapshotException
{
testCollections5(TestSnapshots.getSnapshot(snapfile,false), null);
ISnapshot snapshot = TestSnapshots.getSnapshot(snapfile, false);
assumeThat(snapshot.getSnapshotInfo().getProperty("$heapFormat"), not(equalTo((Serializable)"DTFJ-PHD")));
testCollections5(snapshot, null);
}

@Test
public void testCollections6() throws SnapshotException
{
testCollections6(TestSnapshots.getSnapshot(snapfile,false), null);
ISnapshot snapshot = TestSnapshots.getSnapshot(snapfile, false);
assumeThat(snapshot.getSnapshotInfo().getProperty("$heapFormat"), not(equalTo((Serializable)"DTFJ-PHD")));
testCollections6(snapshot, null);
}
}

0 comments on commit 5b49e1a

Please sign in to comment.