ddmuilib

16:35:03.364 INFO  jd.cli.Main - Decompiling ddmuilib.jar
package com.android.ddmuilib;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class AbstractBufferFindTarget
  implements IFindTarget
{
  private int mCurrentSearchIndex;
  private Pattern mLastSearchPattern;
  private String mLastSearchText;
  
  public boolean findAndSelect(String text, boolean isNewSearch, boolean searchForward)
  {
    boolean found = false;
    int maxIndex = getItemCount();
    synchronized (this)
    {
      if (isNewSearch) {
        mCurrentSearchIndex = getStartingIndex();
      } else {
        mCurrentSearchIndex = getNext(mCurrentSearchIndex, searchForward, maxIndex);
      }
      Pattern pattern;
      Pattern pattern;
      if (text.equals(mLastSearchText))
      {
        pattern = mLastSearchPattern;
      }
      else
      {
        pattern = Pattern.compile(text, 2);
        mLastSearchPattern = pattern;
        mLastSearchText = text;
      }
      int index = mCurrentSearchIndex;
      do
      {
        String msgText = getItem(mCurrentSearchIndex);
        if ((msgText != null) && (pattern.matcher(msgText).find()))
        {
          found = true;
          break;
        }
        mCurrentSearchIndex = getNext(mCurrentSearchIndex, searchForward, maxIndex);
      } while (index != mCurrentSearchIndex);
    }
    if (found) {
      selectAndReveal(mCurrentSearchIndex);
    }
    return found;
  }
  
  public void scrollBy(int delta)
  {
    synchronized (this)
    {
      if (mCurrentSearchIndex > 0) {
        mCurrentSearchIndex = Math.max(0, mCurrentSearchIndex - delta);
      }
    }
  }
  
  private int getNext(int index, boolean searchForward, int max)
  {
    index = searchForward ? index + 1 : index - 1;
    if (index == -1) {
      index = max - 1;
    }
    if (index == max) {
      index = 0;
    }
    return index;
  }
  
  public abstract int getItemCount();
  
  public abstract String getItem(int paramInt);
  
  public abstract void selectAndReveal(int paramInt);
  
  public abstract int getStartingIndex();
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AbstractBufferFindTarget
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.Log;
import com.android.ddmlib.NativeLibraryMapInfo;
import com.android.ddmlib.NativeStackCallInfo;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

public class Addr2Line
{
  private static final String ANDROID_SYMBOLS_ENVVAR = "ANDROID_SYMBOLS";
  private static final String LIBRARY_NOT_FOUND_MESSAGE_FORMAT = "Unable to locate library %s on disk. Addresses mapping to this library will not be resolved. In order to fix this, set the the library search path in the UI, or set the environment variable ANDROID_SYMBOLS.";
  private static final HashMap<String, Addr2Line> sProcessCache = new HashMap();
  private static final byte[] sCrLf = { 10 };
  private NativeLibraryMapInfo mLibrary;
  private Process mProcess;
  private BufferedReader mResultReader;
  private BufferedOutputStream mAddressWriter;
  private static final String DEFAULT_LIBRARY_SYMBOLS_FOLDER;
  
  static
  {
    String symbols = System.getenv("ANDROID_SYMBOLS");
    if (symbols == null) {
      DEFAULT_LIBRARY_SYMBOLS_FOLDER = DdmUiPreferences.getSymbolDirectory();
    } else {
      DEFAULT_LIBRARY_SYMBOLS_FOLDER = symbols;
    }
  }
  
  private static List<String> mLibrarySearchPaths = new ArrayList();
  
  public static void setSearchPath(String path)
  {
    mLibrarySearchPaths.clear();
    mLibrarySearchPaths.addAll(Arrays.asList(path.split(":")));
  }
  
  public static Addr2Line getProcess(NativeLibraryMapInfo library)
  {
    String libName = library.getLibraryName();
    if (libName != null) {
      synchronized (sProcessCache)
      {
        Addr2Line process = (Addr2Line)sProcessCache.get(libName);
        if (process == null)
        {
          process = new Addr2Line(library);
          
          boolean status = process.start();
          if (status) {
            sProcessCache.put(libName, process);
          } else {
            process = null;
          }
        }
        return process;
      }
    }
    return null;
  }
  
  private Addr2Line(NativeLibraryMapInfo library)
  {
    mLibrary = library;
  }
  
  private String getLibraryPath(String library)
  {
    String path = DEFAULT_LIBRARY_SYMBOLS_FOLDER + library;
    if (new File(path).exists()) {
      return path;
    }
    for (String p : mLibrarySearchPaths)
    {
      String fullPath = p + "/" + library;
      if (new File(fullPath).exists()) {
        return fullPath;
      }
      fullPath = p + "/" + new File(library).getName();
      if (new File(fullPath).exists()) {
        return fullPath;
      }
    }
    return null;
  }
  
  private boolean start()
  {
    String addr2Line = System.getenv("ANDROID_ADDR2LINE");
    if (addr2Line == null) {
      addr2Line = DdmUiPreferences.getAddr2Line();
    }
    String[] command = new String[5];
    command[0] = addr2Line;
    command[1] = "-C";
    command[2] = "-f";
    command[3] = "-e";
    
    String fullPath = getLibraryPath(mLibrary.getLibraryName());
    if (fullPath == null)
    {
      String msg = String.format("Unable to locate library %s on disk. Addresses mapping to this library will not be resolved. In order to fix this, set the the library search path in the UI, or set the environment variable ANDROID_SYMBOLS.", new Object[] { mLibrary.getLibraryName() });
      Log.e("ddm-Addr2Line", msg);
      return false;
    }
    command[4] = fullPath;
    try
    {
      mProcess = Runtime.getRuntime().exec(command);
      if (mProcess != null)
      {
        InputStreamReader is = new InputStreamReader(mProcess.getInputStream());
        
        mResultReader = new BufferedReader(is);
        
        mAddressWriter = new BufferedOutputStream(mProcess.getOutputStream());
        if ((mResultReader == null) || (mAddressWriter == null))
        {
          mProcess.destroy();
          mProcess = null;
          return false;
        }
        return true;
      }
    }
    catch (IOException e)
    {
      String msg = String.format("Error while trying to start %1$s process for library %2$s", new Object[] { DdmUiPreferences.getAddr2Line(), mLibrary });
      
      Log.e("ddm-Addr2Line", msg);
      if (mProcess != null)
      {
        mProcess.destroy();
        mProcess = null;
      }
    }
    return false;
  }
  
  public void stop()
  {
    synchronized (sProcessCache)
    {
      if (mProcess != null)
      {
        sProcessCache.remove(mLibrary);
        
        mProcess.destroy();
        
        mProcess = null;
      }
    }
  }
  
  public static void stopAll()
  {
    synchronized (sProcessCache)
    {
      Collection<Addr2Line> col = sProcessCache.values();
      for (Addr2Line a2l : col) {
        a2l.stop();
      }
    }
  }
  
  public NativeStackCallInfo getAddress(long addr)
  {
    long offset = addr - mLibrary.getStartAddress();
    synchronized (sProcessCache)
    {
      if (mProcess != null)
      {
        String tmp = Long.toString(offset, 16);
        try
        {
          mAddressWriter.write(tmp.getBytes());
          
          mAddressWriter.write(sCrLf);
          
          mAddressWriter.flush();
          
          String method = mResultReader.readLine();
          String source = mResultReader.readLine();
          if ((method != null) && (source != null)) {
            return new NativeStackCallInfo(addr, mLibrary.getLibraryName(), method, source);
          }
        }
        catch (IOException e)
        {
          Log.e("ddms", "Error while trying to get information for addr: " + tmp + " in library: " + mLibrary);
        }
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.Addr2Line
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.Client;
import com.android.ddmlib.ClientData;
import com.android.ddmlib.ClientData.AllocationTrackingStatus;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AllocationPanel$1
  extends SelectionAdapter
{
  AllocationPanel$1(AllocationPanel paramAllocationPanel) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    Client current = this$0.getCurrentClient();
    ClientData.AllocationTrackingStatus status = current.getClientData().getAllocationStatus();
    if (status == ClientData.AllocationTrackingStatus.ON) {
      current.enableAllocationTracker(false);
    } else {
      current.enableAllocationTracker(true);
    }
    current.requestAllocationStatus();
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo.SortMode;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TableColumn;

class AllocationPanel$10
  extends SelectionAdapter
{
  AllocationPanel$10(AllocationPanel paramAllocationPanel, TableColumn paramTableColumn) {}
  
  public void widgetSelected(SelectionEvent arg0)
  {
    AllocationPanel.access$400(this$0, val$inMethodCol, AllocationInfo.SortMode.IN_METHOD);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.10
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;

class AllocationPanel$11
  implements ISelectionChangedListener
{
  AllocationPanel$11(AllocationPanel paramAllocationPanel) {}
  
  public void selectionChanged(SelectionChangedEvent event)
  {
    AllocationInfo selectedAlloc = AllocationPanel.access$700(this$0, event.getSelection());
    AllocationPanel.access$800(this$0, selectedAlloc);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.11
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;

class AllocationPanel$12
  implements Listener
{
  AllocationPanel$12(AllocationPanel paramAllocationPanel, Sash paramSash, FormData paramFormData, IPreferenceStore paramIPreferenceStore) {}
  
  public void handleEvent(Event e)
  {
    Rectangle sashRect = val$sash.getBounds();
    Rectangle panelRect = AllocationPanel.access$900(this$0).getClientArea();
    int bottom = height - height - 100;
    y = Math.max(Math.min(y, bottom), 100);
    if (y != y)
    {
      val$sashData.top = new FormAttachment(0, y);
      val$store.setValue("allocPanel.sash", y);
      AllocationPanel.access$900(this$0).layout();
    }
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.12
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import org.eclipse.jface.viewers.TableViewer;

class AllocationPanel$13
  implements Runnable
{
  AllocationPanel$13(AllocationPanel paramAllocationPanel) {}
  
  public void run()
  {
    AllocationPanel.access$300(this$0).refresh();
    AllocationPanel.access$1000(this$0);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.13
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.Client;
import com.android.ddmlib.ClientData;

class AllocationPanel$14
  implements Runnable
{
  AllocationPanel$14(AllocationPanel paramAllocationPanel, Client paramClient) {}
  
  public void run()
  {
    AllocationPanel.access$1100(this$0, true, val$client.getClientData().getAllocationStatus());
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.14
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

class AllocationPanel$15 {}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.15
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.Client;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AllocationPanel$2
  extends SelectionAdapter
{
  AllocationPanel$2(AllocationPanel paramAllocationPanel) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    this$0.getCurrentClient().requestAllocationDetails();
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Text;

class AllocationPanel$3
  implements ModifyListener
{
  AllocationPanel$3(AllocationPanel paramAllocationPanel, Text paramText) {}
  
  public void modifyText(ModifyEvent arg0)
  {
    AllocationPanel.access$002(this$0, val$filterText.getText().trim());
    AllocationPanel.access$300(this$0).refresh();
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AllocationPanel$4
  extends SelectionAdapter
{
  AllocationPanel$4(AllocationPanel paramAllocationPanel) {}
  
  public void widgetSelected(SelectionEvent arg0)
  {
    AllocationPanel.access$300(this$0).refresh();
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.4
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo.SortMode;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TableColumn;

class AllocationPanel$5
  extends SelectionAdapter
{
  AllocationPanel$5(AllocationPanel paramAllocationPanel, TableColumn paramTableColumn) {}
  
  public void widgetSelected(SelectionEvent arg0)
  {
    AllocationPanel.access$400(this$0, val$numberCol, AllocationInfo.SortMode.NUMBER);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.5
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo.SortMode;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TableColumn;

class AllocationPanel$6
  extends SelectionAdapter
{
  AllocationPanel$6(AllocationPanel paramAllocationPanel, TableColumn paramTableColumn) {}
  
  public void widgetSelected(SelectionEvent arg0)
  {
    AllocationPanel.access$400(this$0, val$sizeCol, AllocationInfo.SortMode.SIZE);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.6
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo.SortMode;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TableColumn;

class AllocationPanel$7
  extends SelectionAdapter
{
  AllocationPanel$7(AllocationPanel paramAllocationPanel, TableColumn paramTableColumn) {}
  
  public void widgetSelected(SelectionEvent arg0)
  {
    AllocationPanel.access$400(this$0, val$classCol, AllocationInfo.SortMode.CLASS);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.7
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo.SortMode;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TableColumn;

class AllocationPanel$8
  extends SelectionAdapter
{
  AllocationPanel$8(AllocationPanel paramAllocationPanel, TableColumn paramTableColumn) {}
  
  public void widgetSelected(SelectionEvent arg0)
  {
    AllocationPanel.access$400(this$0, val$threadCol, AllocationInfo.SortMode.THREAD);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.8
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo.SortMode;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TableColumn;

class AllocationPanel$9
  extends SelectionAdapter
{
  AllocationPanel$9(AllocationPanel paramAllocationPanel, TableColumn paramTableColumn) {}
  
  public void widgetSelected(SelectionEvent arg0)
  {
    AllocationPanel.access$400(this$0, val$inClassCol, AllocationInfo.SortMode.IN_CLASS);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.9
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo;
import com.android.ddmlib.Client;
import com.android.ddmlib.ClientData;
import java.util.Arrays;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;

class AllocationPanel$AllocationContentProvider
  implements IStructuredContentProvider
{
  private AllocationPanel$AllocationContentProvider(AllocationPanel paramAllocationPanel) {}
  
  public Object[] getElements(Object inputElement)
  {
    if ((inputElement instanceof Client))
    {
      AllocationInfo[] allocs = ((Client)inputElement).getClientData().getAllocations();
      if (allocs != null)
      {
        if ((AllocationPanel.access$000(this$0) != null) && (AllocationPanel.access$000(this$0).length() > 0)) {
          allocs = AllocationPanel.access$100(this$0, allocs, AllocationPanel.access$000(this$0));
        }
        Arrays.sort(allocs, AllocationPanel.access$200(this$0));
        return allocs;
      }
    }
    return new Object[0];
  }
  
  public void dispose() {}
  
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.AllocationContentProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

class AllocationPanel$AllocationLabelProvider
  implements ITableLabelProvider
{
  public Image getColumnImage(Object element, int columnIndex)
  {
    return null;
  }
  
  public String getColumnText(Object element, int columnIndex)
  {
    if ((element instanceof AllocationInfo))
    {
      AllocationInfo alloc = (AllocationInfo)element;
      switch (columnIndex)
      {
      case 0: 
        return Integer.toString(alloc.getAllocNumber());
      case 1: 
        return Integer.toString(alloc.getSize());
      case 2: 
        return alloc.getAllocatedClass();
      case 3: 
        return Short.toString(alloc.getThreadId());
      case 4: 
        return alloc.getFirstTraceClassName();
      case 5: 
        return alloc.getFirstTraceMethodName();
      }
    }
    return null;
  }
  
  public void addListener(ILabelProviderListener listener) {}
  
  public void dispose() {}
  
  public boolean isLabelProperty(Object element, String property)
  {
    return false;
  }
  
  public void removeListener(ILabelProviderListener listener) {}
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel.AllocationLabelProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.AllocationInfo;
import com.android.ddmlib.AllocationInfo.AllocationSorter;
import com.android.ddmlib.AllocationInfo.SortMode;
import com.android.ddmlib.Client;
import com.android.ddmlib.ClientData;
import com.android.ddmlib.ClientData.AllocationTrackingStatus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

public class AllocationPanel
  extends TablePanel
{
  private static final String PREFS_ALLOC_COL_NUMBER = "allocPanel.Col00";
  private static final String PREFS_ALLOC_COL_SIZE = "allocPanel.Col0";
  private static final String PREFS_ALLOC_COL_CLASS = "allocPanel.Col1";
  private static final String PREFS_ALLOC_COL_THREAD = "allocPanel.Col2";
  private static final String PREFS_ALLOC_COL_TRACE_CLASS = "allocPanel.Col3";
  private static final String PREFS_ALLOC_COL_TRACE_METHOD = "allocPanel.Col4";
  private static final String PREFS_ALLOC_SASH = "allocPanel.sash";
  private static final String PREFS_STACK_COLUMN = "allocPanel.stack.col0";
  private Composite mAllocationBase;
  private Table mAllocationTable;
  private TableViewer mAllocationViewer;
  private StackTracePanel mStackTracePanel;
  private Table mStackTraceTable;
  private Button mEnableButton;
  private Button mRequestButton;
  private Button mTraceFilterCheck;
  private final AllocationInfo.AllocationSorter mSorter;
  private TableColumn mSortColumn;
  private Image mSortUpImg;
  private Image mSortDownImg;
  private String mFilterText;
  
  public AllocationPanel()
  {
    mSorter = new AllocationInfo.AllocationSorter();
    
    mFilterText = null;
  }
  
  private class AllocationContentProvider
    implements IStructuredContentProvider
  {
    private AllocationContentProvider() {}
    
    public Object[] getElements(Object inputElement)
    {
      if ((inputElement instanceof Client))
      {
        AllocationInfo[] allocs = ((Client)inputElement).getClientData().getAllocations();
        if (allocs != null)
        {
          if ((mFilterText != null) && (mFilterText.length() > 0)) {
            allocs = AllocationPanel.this.getFilteredAllocations(allocs, mFilterText);
          }
          Arrays.sort(allocs, mSorter);
          return allocs;
        }
      }
      return new Object[0];
    }
    
    public void dispose() {}
    
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
  }
  
  private static class AllocationLabelProvider
    implements ITableLabelProvider
  {
    public Image getColumnImage(Object element, int columnIndex)
    {
      return null;
    }
    
    public String getColumnText(Object element, int columnIndex)
    {
      if ((element instanceof AllocationInfo))
      {
        AllocationInfo alloc = (AllocationInfo)element;
        switch (columnIndex)
        {
        case 0: 
          return Integer.toString(alloc.getAllocNumber());
        case 1: 
          return Integer.toString(alloc.getSize());
        case 2: 
          return alloc.getAllocatedClass();
        case 3: 
          return Short.toString(alloc.getThreadId());
        case 4: 
          return alloc.getFirstTraceClassName();
        case 5: 
          return alloc.getFirstTraceMethodName();
        }
      }
      return null;
    }
    
    public void addListener(ILabelProviderListener listener) {}
    
    public void dispose() {}
    
    public boolean isLabelProperty(Object element, String property)
    {
      return false;
    }
    
    public void removeListener(ILabelProviderListener listener) {}
  }
  
  protected Control createControl(Composite parent)
  {
    final IPreferenceStore store = DdmUiPreferences.getStore();
    
    Display display = parent.getDisplay();
    
    mSortUpImg = ImageLoader.getDdmUiLibLoader().loadImage("sort_up.png", display);
    mSortDownImg = ImageLoader.getDdmUiLibLoader().loadImage("sort_down.png", display);
    
    mAllocationBase = new Composite(parent, 0);
    mAllocationBase.setLayout(new FormLayout());
    
    Composite topParent = new Composite(mAllocationBase, 0);
    topParent.setLayout(new GridLayout(6, false));
    
    mEnableButton = new Button(topParent, 8);
    mEnableButton.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        Client current = getCurrentClient();
        ClientData.AllocationTrackingStatus status = current.getClientData().getAllocationStatus();
        if (status == ClientData.AllocationTrackingStatus.ON) {
          current.enableAllocationTracker(false);
        } else {
          current.enableAllocationTracker(true);
        }
        current.requestAllocationStatus();
      }
    });
    mRequestButton = new Button(topParent, 8);
    mRequestButton.setText("Get Allocations");
    mRequestButton.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        getCurrentClient().requestAllocationDetails();
      }
    });
    setUpButtons(false, ClientData.AllocationTrackingStatus.OFF);
    
    Composite spacer = new Composite(topParent, 0);
    GridData gridData;
    spacer.setLayoutData(gridData = new GridData(768));
    
    new Label(topParent, 0).setText("Filter:");
    
    final Text filterText = new Text(topParent, 2048);
    filterText.setLayoutData(gridData = new GridData(768));
    widthHint = 200;
    
    filterText.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent arg0)
      {
        mFilterText = filterText.getText().trim();
        mAllocationViewer.refresh();
      }
    });
    mTraceFilterCheck = new Button(topParent, 32);
    mTraceFilterCheck.setText("Inc. trace");
    mTraceFilterCheck.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent arg0)
      {
        mAllocationViewer.refresh();
      }
    });
    mAllocationTable = new Table(topParent, 65538);
    mAllocationTable.setLayoutData(gridData = new GridData(1808));
    horizontalSpan = 6;
    mAllocationTable.setHeaderVisible(true);
    mAllocationTable.setLinesVisible(true);
    
    final TableColumn numberCol = TableHelper.createTableColumn(mAllocationTable, "Alloc Order", 131072, "Alloc Order", "allocPanel.Col00", store);
    
    numberCol.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent arg0)
      {
        AllocationPanel.this.setSortColumn(numberCol, AllocationInfo.SortMode.NUMBER);
      }
    });
    final TableColumn sizeCol = TableHelper.createTableColumn(mAllocationTable, "Allocation Size", 131072, "888", "allocPanel.Col0", store);
    
    sizeCol.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent arg0)
      {
        AllocationPanel.this.setSortColumn(sizeCol, AllocationInfo.SortMode.SIZE);
      }
    });
    final TableColumn classCol = TableHelper.createTableColumn(mAllocationTable, "Allocated Class", 16384, "Allocated Class", "allocPanel.Col1", store);
    
    classCol.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent arg0)
      {
        AllocationPanel.this.setSortColumn(classCol, AllocationInfo.SortMode.CLASS);
      }
    });
    final TableColumn threadCol = TableHelper.createTableColumn(mAllocationTable, "Thread Id", 16384, "999", "allocPanel.Col2", store);
    
    threadCol.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent arg0)
      {
        AllocationPanel.this.setSortColumn(threadCol, AllocationInfo.SortMode.THREAD);
      }
    });
    final TableColumn inClassCol = TableHelper.createTableColumn(mAllocationTable, "Allocated in", 16384, "utime", "allocPanel.Col3", store);
    
    inClassCol.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent arg0)
      {
        AllocationPanel.this.setSortColumn(inClassCol, AllocationInfo.SortMode.IN_CLASS);
      }
    });
    final TableColumn inMethodCol = TableHelper.createTableColumn(mAllocationTable, "Allocated in", 16384, "utime", "allocPanel.Col4", store);
    
    inMethodCol.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent arg0)
      {
        AllocationPanel.this.setSortColumn(inMethodCol, AllocationInfo.SortMode.IN_METHOD);
      }
    });
    switch (mSorter.getSortMode())
    {
    case SIZE: 
      mSortColumn = sizeCol;
      break;
    case CLASS: 
      mSortColumn = classCol;
      break;
    case THREAD: 
      mSortColumn = threadCol;
      break;
    case IN_CLASS: 
      mSortColumn = inClassCol;
      break;
    case IN_METHOD: 
      mSortColumn = inMethodCol;
    }
    mSortColumn.setImage(mSorter.isDescending() ? mSortDownImg : mSortUpImg);
    
    mAllocationViewer = new TableViewer(mAllocationTable);
    mAllocationViewer.setContentProvider(new AllocationContentProvider(null));
    mAllocationViewer.setLabelProvider(new AllocationLabelProvider(null));
    
    mAllocationViewer.addSelectionChangedListener(new ISelectionChangedListener()
    {
      public void selectionChanged(SelectionChangedEvent event)
      {
        AllocationInfo selectedAlloc = AllocationPanel.this.getAllocationSelection(event.getSelection());
        AllocationPanel.this.updateAllocationStackTrace(selectedAlloc);
      }
    });
    final Sash sash = new Sash(mAllocationBase, 256);
    Color darkGray = parent.getDisplay().getSystemColor(16);
    sash.setBackground(darkGray);
    
    mStackTracePanel = new StackTracePanel();
    mStackTraceTable = mStackTracePanel.createPanel(mAllocationBase, "allocPanel.stack.col0", store);
    
    FormData data = new FormData();
    top = new FormAttachment(0, 0);
    bottom = new FormAttachment(sash, 0);
    left = new FormAttachment(0, 0);
    right = new FormAttachment(100, 0);
    topParent.setLayoutData(data);
    
    final FormData sashData = new FormData();
    if ((store != null) && (store.contains("allocPanel.sash"))) {
      top = new FormAttachment(0, store.getInt("allocPanel.sash"));
    } else {
      top = new FormAttachment(50, 0);
    }
    left = new FormAttachment(0, 0);
    right = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);
    
    data = new FormData();
    top = new FormAttachment(sash, 0);
    bottom = new FormAttachment(100, 0);
    left = new FormAttachment(0, 0);
    right = new FormAttachment(100, 0);
    mStackTraceTable.setLayoutData(data);
    
    sash.addListener(13, new Listener()
    {
      public void handleEvent(Event e)
      {
        Rectangle sashRect = sash.getBounds();
        Rectangle panelRect = mAllocationBase.getClientArea();
        int bottom = height - height - 100;
        y = Math.max(Math.min(y, bottom), 100);
        if (y != y)
        {
          sashDatatop = new FormAttachment(0, y);
          store.setValue("allocPanel.sash", y);
          mAllocationBase.layout();
        }
      }
    });
    return mAllocationBase;
  }
  
  public void dispose()
  {
    mSortUpImg.dispose();
    mSortDownImg.dispose();
    super.dispose();
  }
  
  public void setFocus()
  {
    mAllocationTable.setFocus();
  }
  
  public void clientChanged(final Client client, int changeMask)
  {
    if (client == getCurrentClient()) {
      if ((changeMask & 0x200) != 0) {
        try
        {
          mAllocationTable.getDisplay().asyncExec(new Runnable()
          {
            public void run()
            {
              mAllocationViewer.refresh();
              AllocationPanel.this.updateAllocationStackCall();
            }
          });
        }
        catch (SWTException e) {}
      } else if ((changeMask & 0x400) != 0) {
        try
        {
          mAllocationTable.getDisplay().asyncExec(new Runnable()
          {
            public void run()
            {
              AllocationPanel.this.setUpButtons(true, client.getClientData().getAllocationStatus());
            }
          });
        }
        catch (SWTException e) {}
      }
    }
  }
  
  public void deviceSelected() {}
  
  public void clientSelected()
  {
    if (mAllocationTable.isDisposed()) {
      return;
    }
    Client client = getCurrentClient();
    
    mStackTracePanel.setCurrentClient(client);
    mStackTracePanel.setViewerInput(null);
    if (client != null) {
      setUpButtons(true, client.getClientData().getAllocationStatus());
    } else {
      setUpButtons(false, ClientData.AllocationTrackingStatus.OFF);
    }
    mAllocationViewer.setInput(client);
  }
  
  private void updateAllocationStackCall()
  {
    Client client = getCurrentClient();
    if (client != null)
    {
      AllocationInfo selectedAlloc = getAllocationSelection(null);
      if (selectedAlloc != null) {
        updateAllocationStackTrace(selectedAlloc);
      } else {
        updateAllocationStackTrace(null);
      }
    }
  }
  
  private void updateAllocationStackTrace(AllocationInfo alloc)
  {
    mStackTracePanel.setViewerInput(alloc);
  }
  
  protected void setTableFocusListener()
  {
    addTableToFocusListener(mAllocationTable);
    addTableToFocusListener(mStackTraceTable);
  }
  
  private AllocationInfo getAllocationSelection(ISelection selection)
  {
    if (selection == null) {
      selection = mAllocationViewer.getSelection();
    }
    if ((selection instanceof IStructuredSelection))
    {
      IStructuredSelection structuredSelection = (IStructuredSelection)selection;
      Object object = structuredSelection.getFirstElement();
      if ((object instanceof AllocationInfo)) {
        return (AllocationInfo)object;
      }
    }
    return null;
  }
  
  private void setUpButtons(boolean enabled, ClientData.AllocationTrackingStatus trackingStatus)
  {
    if (enabled)
    {
      switch (trackingStatus)
      {
      case UNKNOWN: 
        mEnableButton.setText("?");
        mEnableButton.setEnabled(false);
        mRequestButton.setEnabled(false);
        break;
      case OFF: 
        mEnableButton.setText("Start Tracking");
        mEnableButton.setEnabled(true);
        mRequestButton.setEnabled(false);
        break;
      case ON: 
        mEnableButton.setText("Stop Tracking");
        mEnableButton.setEnabled(true);
        mRequestButton.setEnabled(true);
      }
    }
    else
    {
      mEnableButton.setEnabled(false);
      mRequestButton.setEnabled(false);
      mEnableButton.setText("Start Tracking");
    }
  }
  
  private void setSortColumn(TableColumn column, AllocationInfo.SortMode sortMode)
  {
    mSorter.setSortMode(sortMode);
    
    mAllocationTable.setRedraw(false);
    if (mSortColumn != column) {
      mSortColumn.setImage(null);
    }
    mSortColumn = column;
    if (mSorter.isDescending()) {
      mSortColumn.setImage(mSortDownImg);
    } else {
      mSortColumn.setImage(mSortUpImg);
    }
    mAllocationTable.setRedraw(true);
    mAllocationViewer.refresh();
  }
  
  private AllocationInfo[] getFilteredAllocations(AllocationInfo[] allocations, String filterText)
  {
    ArrayList<AllocationInfo> results = new ArrayList();
    
    Locale locale = Locale.getDefault();
    filterText = filterText.toLowerCase(locale);
    boolean fullTrace = mTraceFilterCheck.getSelection();
    for (AllocationInfo info : allocations) {
      if (info.filter(filterText, fullTrace, locale)) {
        results.add(info);
      }
    }
    return (AllocationInfo[])results.toArray(new AllocationInfo[results.size()]);
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.AllocationPanel
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.Log;

public abstract class BackgroundThread
  extends Thread
{
  private boolean mQuit = false;
  
  public final void quit()
  {
    mQuit = true;
    Log.d("ddms", "Waiting for BackgroundThread to quit");
    try
    {
      join();
    }
    catch (InterruptedException ie)
    {
      ie.printStackTrace();
    }
  }
  
  protected final boolean isQuitting()
  {
    return mQuit;
  }
}

/* Location:
 * Qualified Name:     com.android.ddmuilib.BackgroundThread
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ddmuilib;

import com.android.ddmlib.ClientData.HeapData;
import com.android.ddmlib.HeapSegment;
import com.android.ddmlib.HeapSegment.HeapSegmentElement;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;

public abstract class BaseHeapPanel
  extends TablePanel
{
  protected byte[] mProcessedHeapData;
  private Map<Integer, ArrayList<HeapSegment.HeapSegmentElement>> mHeapMap;
  
  protected boolean serializeHeapData(ClientData.HeapData heapData)
  {
    synchronized (heapData)
    {
      Collection<HeapSegment> heapSegments = heapData.getHeapSegments();
      if (heapSegments != null)
      {
        heapData.clearHeapData();
        
        doSerializeHeapData(heapSegments);
        heapData.setProcessedHeapData(mProcessedHeapData);
        heapData.setProcessedHeapMap(mHeapMap);
      }
      else
      {
        byte[] pixData = heapData.getProcessedHeapData();
        if (pixData == mProcessedHeapData) {
          return false;
        }
        mProcessedHeapData = pixData;
        
        Map<Integer, ArrayList<HeapSegment.HeapSegmentElement>> heapMap = heapData.getProcessedHeapMap();
        
        mHeapMap = heapMap;
      }
    }
    return true;
  }
  
  protected byte[] getSerializedData()
  {
    return mProcessedHeapData;
  }
  
  private void doSerializeHeapData(Collection<HeapSegment> heapData)
  {
    mHeapMap = new TreeMap();
    
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd