OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [gcj/] [tools/] [gc_analyze/] [SymbolLookup.java] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
/* SymbolLookup.java -- Finds class names by analyzing memory.
2
   Copyright (C) 2007  Free Software Foundation
3
 
4
   This file is part of libgcj.
5
 
6
   This software is copyrighted work licensed under the terms of the
7
   Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
8
   details.  */
9
 
10
package gnu.gcj.tools.gc_analyze;
11
 
12
import java.io.BufferedReader;
13
import java.io.IOException;
14
 
15
class SymbolLookup
16
{
17
  MemoryMap memoryMap;
18
 
19
  public SymbolLookup(BufferedReader reader,
20
                      String rawFileName)
21
    throws IOException
22
  {
23
    memoryMap = new MemoryMap(reader, rawFileName);
24
  }
25
 
26
  public String decodeUTF8(long address) throws IOException
27
  {
28
    return decodeUTF8(address, -1);
29
  }
30
 
31
  public String decodeUTF8(long address, int limit) throws IOException
32
  {
33
    if (address == 0)
34
      return null;
35
 
36
    BytePtr utf8 = memoryMap.getBytePtr(address, 64);
37
 
38
    if (utf8 == null)
39
      return null;
40
 
41
    int len = utf8.getShort(1);
42
    int hash16 = utf8.getShort(0) & 0xffff;
43
 
44
    if (len <= 0 || (limit > 0 && len > (limit - 4)))
45
      return null;
46
 
47
    if (len > utf8.getsize() + 4)
48
      utf8 = memoryMap.getBytePtr(address, len + 4);
49
 
50
    if (utf8 == null)
51
      return null;
52
 
53
    StringBuilder sb = new StringBuilder(len);
54
    int pos = 4;
55
    len += 4;
56
 
57
    while (pos < len)
58
      {
59
        int f = utf8.getByte(pos++);
60
        if ((f & 0x80) == 0)
61
          {
62
            sb.append((char)f);
63
          }
64
        else if ((f & 0xe0) == 0xc0)
65
          {
66
            int s = utf8.getByte(pos++);
67
            char c = (char)(((f & 0x1f) << 6) | (s & 0x80));
68
            sb.append(c);
69
          }
70
        else if ((f & 0xe0) == 0xe0)
71
          {
72
            int s = utf8.getByte(pos++);
73
            int t = utf8.getByte(pos++);
74
            char c = (char)(((f & 0x0f) << 12)
75
                            | ((s & 0x80) << 6) | (t & 0x80));
76
            sb.append(c);
77
          }
78
        else
79
          break;  // Bad utf8
80
      }
81
    String rv = sb.toString();
82
    if (hash16 == (rv.hashCode() & 0xffff))
83
      return rv;
84
    else
85
      return null;
86
  }
87
 
88
  public String getSymbolViaVtable(long address) throws IOException
89
  {
90
    return memoryMap.getSymbol(address);
91
  }
92
 
93
  public String getSymbol(long address) throws IOException
94
  {
95
    String symbol = memoryMap.getSymbol(address);
96
    if (null != symbol)
97
      return symbol;
98
 
99
    BytePtr klass = memoryMap.getBytePtr(address, 3 * memoryMap.wordSize);
100
    if (klass == null)
101
      return null;
102
 
103
    long nameUTF8p = klass.getWord(2);
104
 
105
    return decodeUTF8(nameUTF8p);
106
  }
107
 
108
  BytePtr getBytePtr(long addr, int length) throws IOException
109
  {
110
    return memoryMap.getBytePtr(addr, length);
111
  }
112
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.