gcc/libjava/gnu/gcj/tools/gc_analyze/SymbolLookup.java
David Daney 7f40378f06 Make-lang.in (JAVA_MANFILES): Add doc/gc-analyze.1.
gcc/java:
2007-02-15  David Daney  <ddaney@avtrex.com>

	* Make-lang.in (JAVA_MANFILES): Add doc/gc-analyze.1.
	(java.maintainer-clean):Add gc-analyze.1.
	(.INTERMEDIATE): Add gc-analyze.pod.
	(gc-analyze.pod): New rule.
	(java.install-man): Install gc-analyze.1
	* gcj.texi: Add new section for the gc-analyze program.

libjava:
2007-02-15  Johannes Schmidt  <jschmidt@avtrex.com>
	David Daney  <ddaney@avtrex.com>

	* configure.ac: Create vm-tools-packages file.  Add 
	gnu/gcj/tools/gc_analyze to standard.omit and vm-tools-packages.
	Check for /proc/self/maps.
	* Makefile.am (bin_PROGRAMS): Added gc-analyze.
	(gc_analyze_SOURCES): New.
	(gc_analyze_LDFLAGS): New.
	(gc_analyze_LINK): New.
	(gc_analyze_LDADD): New.
	(gc_analyze_DEPENDENCIES): New.
	(nat_source_files): Add gnu/gcj/util/natGCInfo.cc.
	* Makefile.in: Regenerated.
	* configure: Regenerated.
	* include/config.h.in: Regenerated.
	* sources.am: Regenerated.
	* scripts/makemake.tcl: Don't include gc-analyze classes in libgcj.
	* gnu/gcj/tools/gc_analyze/SymbolLookup.java: New.
	* gnu/gcj/tools/gc_analyze/ObjectMap.java: New.
	* gnu/gcj/tools/gc_analyze/MemoryMap.java: New.
	* gnu/gcj/tools/gc_analyze/SymbolTable.java: New.
	* gnu/gcj/tools/gc_analyze/BlockMap.java: New.
	* gnu/gcj/tools/gc_analyze/BytePtr.java: New.
	* gnu/gcj/tools/gc_analyze/ItemList.java: New.
	* gnu/gcj/tools/gc_analyze/ToolPrefix.java: New.
	* gnu/gcj/tools/gc_analyze/MemoryAnalyze.java: New.
	* gnu/gcj/util/GCInfo.java: New.
	* gnu/gcj/util/GCInfo.h: New.
	* gnu/gcj/util/natGCInfo.cc: New.
	* gnu/gcj/util/UtilPermission.java: New.
	* gnu/gcj/util/UtilPermission.h: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/SymbolTable.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/ObjectMap$ObjectItem.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryMap$RangeComparator.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/BlockMap$PtrMarks.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryMap$Range.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/BlockMap.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/BytePtr.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze$SubstringComparator.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/ItemList.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/ToolPrefix.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze$1$Info.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze$1.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze$2.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze$3.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze$4.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryAnalyze$OptionParser.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/BlockMap$SizeKind.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/SymbolLookup.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/ObjectMap.class: New.
	* classpath/tools/gnu/gcj/tools/gc_analyze/MemoryMap.class: New.
	* classpath/lib/gnu/gcj/util/GCInfo.class: New.
	* classpath/lib/gnu/gcj/util/UtilPermission.class: New.

libjava/classpath:
2007-02-15  David Daney  <ddaney@avtrex.com>

	* tools/Makefile.am (TOOLS_ZIP): Add classes from vm-tools-packages.
	* tools/Makefile.in: Regenerated.

From-SVN: r122007
2007-02-15 17:25:24 +00:00

113 lines
2.6 KiB
Java

/* SymbolLookup.java -- Finds class names by analyzing memory.
Copyright (C) 2007 Free Software Foundation
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package gnu.gcj.tools.gc_analyze;
import java.io.BufferedReader;
import java.io.IOException;
class SymbolLookup
{
MemoryMap memoryMap;
public SymbolLookup(BufferedReader reader,
String rawFileName)
throws IOException
{
memoryMap = new MemoryMap(reader, rawFileName);
}
public String decodeUTF8(long address) throws IOException
{
return decodeUTF8(address, -1);
}
public String decodeUTF8(long address, int limit) throws IOException
{
if (address == 0)
return null;
BytePtr utf8 = memoryMap.getBytePtr(address, 64);
if (utf8 == null)
return null;
int len = utf8.getShort(1);
int hash16 = utf8.getShort(0) & 0xffff;
if (len <= 0 || (limit > 0 && len > (limit - 4)))
return null;
if (len > utf8.getsize() + 4)
utf8 = memoryMap.getBytePtr(address, len + 4);
if (utf8 == null)
return null;
StringBuilder sb = new StringBuilder(len);
int pos = 4;
len += 4;
while (pos < len)
{
int f = utf8.getByte(pos++);
if ((f & 0x80) == 0)
{
sb.append((char)f);
}
else if ((f & 0xe0) == 0xc0)
{
int s = utf8.getByte(pos++);
char c = (char)(((f & 0x1f) << 6) | (s & 0x80));
sb.append(c);
}
else if ((f & 0xe0) == 0xe0)
{
int s = utf8.getByte(pos++);
int t = utf8.getByte(pos++);
char c = (char)(((f & 0x0f) << 12)
| ((s & 0x80) << 6) | (t & 0x80));
sb.append(c);
}
else
break; // Bad utf8
}
String rv = sb.toString();
if (hash16 == (rv.hashCode() & 0xffff))
return rv;
else
return null;
}
public String getSymbolViaVtable(long address) throws IOException
{
return memoryMap.getSymbol(address);
}
public String getSymbol(long address) throws IOException
{
String symbol = memoryMap.getSymbol(address);
if (null != symbol)
return symbol;
BytePtr klass = memoryMap.getBytePtr(address, 3 * memoryMap.wordSize);
if (klass == null)
return null;
long nameUTF8p = klass.getWord(2);
return decodeUTF8(nameUTF8p);
}
BytePtr getBytePtr(long addr, int length) throws IOException
{
return memoryMap.getBytePtr(addr, length);
}
}